package com.lindroy.androidplayer.utils

import android.text.Html
import android.widget.TableLayout
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import com.lindroy.androidplayer.R
import com.lindroy.lib_utils.extensions.getResDrawable

/**
 * @author Lin
 * @date 2022/1/20
 * @function
 */

fun RecyclerView.addSimpleDivider() = this.apply {
    getResDrawable(R.drawable.list_divider)?.also{
        addItemDecoration(
            DividerItemDecoration(
                this.context,
                RecyclerView.VERTICAL
            ).apply {
                setDrawable(it)
            })
    }
}

fun TabLayout.contactToViewPager(viewPager:ViewPager2,titles:List<String>){
    TabLayoutMediator(this, viewPager) { tab, position ->
        tab.text = Html.fromHtml(titles[position])
    }.attach()
}